<link rel="stylesheet" href="__STATIC__/style/login.css" media="all">
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="oldpassword"></label>
                <input type="password" name="oldpassword" id="oldpassword" lay-verify="required|pass" placeholder="原始密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required|pass" placeholder="新密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
                <input type="password" name="renewpassword" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid layui-btn-normal" lay-submit lay-filter="LAY-user-forget-submit">修改密码</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        form.on('submit(LAY-user-forget-submit)', function(data){
            var field = data.field; //获取提交的字段
            if(field.password.length<6 ||field.password.length>20 ){
                return layer.msg('密码长度介于6-20之间',{icon:5,time:1000});
            }
            if(field.password !== field.renewpassword){
                return layer.msg('两次密码输入不一致',{icon:5,time:1000});
            }

            $.post("{:url('admin/site/changePassword')}",field,function (ret) {
                if (ret.code == 0){
                    layer.msg(ret.msg,{icon:6,time:1000},function () {
                        window.location.href = "{:url('admin/site/logout')}";
                    })
                }else{
                    layer.msg(ret.msg,{icon:5,time:1000})
                }
            });
        });
    });
</script>
